import { Module } from '@nestjs/common'
import { ConfigModule } from '@nestjs/config'
import { UploadModule } from './upload/upload.module'
import { PrismaBaseModule } from './prisma-base/prisma-base.module'
import { JwtSerategy } from './strategy/jwt.strategy'
import { ErrorModule } from './filter/error/error.module'
import { RedisModule } from './redis/redis.module'
import { EmailModule } from './pc/email/email.module'
import { AdminUserModule } from './pc/admin-user/admin-user.module'
import { WxUserModule } from './wxapp/wx-user/wx-user.module'
import { DictModule } from './pc/dict/dict.module'
import { DictItemModule } from './pc/dict-item/dict-item.module'
import { WxApiModule } from './wxapp/wx-api/wx-api.module'
import { TimeWorkerModule } from './time-worker/time-worker.module'
import { ScheduleModule } from '@nestjs/schedule'
import { ContractsModule } from './pc/contracts/contracts.module'
import { BannerModule } from './pc/banner/banner.module'
import { HouseResModule } from './pc/house-res/house-res.module'
import { HouseMediaModule } from './pc/house-media/house-media.module'
import { VerRecordModule } from './pc/ver-record/ver-record.module'
import { WinstonModule } from 'nest-winston'
import { format, transports } from 'winston'
import 'winston-daily-rotate-file'

@Module({
  imports: [
    PrismaBaseModule,
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    ScheduleModule.forRoot(),
    WinstonModule.forRoot({
      transports: [
        new transports.DailyRotateFile({
          level: 'error',
          dirname: `logs\\error`,
          filename: `error/%DATE%.log`,
          datePattern: 'YYYY-MM-DD',
          zippedArchive: true,
          maxSize: '20m',
          maxFiles: '14d',
          format: format.combine(
            format.timestamp({
              format: 'YYYY-MM-DD HH:mm:ss',
            }),
            format.printf(
              (info) =>
                `${info.timestamp} [${info.level}]: ${info.message} ${
                  Object.keys(info).length ? JSON.stringify(info, null, 2) : ''
                }`,
            ),
          ),
        }),
      ],
    }),
    ErrorModule,
    UploadModule,
    ErrorModule,
    RedisModule,
    EmailModule,
    AdminUserModule,
    WxUserModule,
    DictModule,
    DictItemModule,
    WxApiModule,
    TimeWorkerModule,
    ContractsModule,
    BannerModule,
    HouseResModule,
    HouseMediaModule,
    VerRecordModule,
  ],
  providers: [JwtSerategy],
})
export class AppModule {}
